<template>
  <div>
    <sell-header :sell="sell"></sell-header>
    <sell-tab :tabs="tabs"></sell-tab>
  </div>

</template>

<script>
import sellHeader from 'components/header/sell-header'
import sellTab from 'components/tab/tab'
import sellGoods from 'components/goods/goods'
import sellRatings from 'components/ratings/ratings'
import sellShop from 'components/shop/shop'
import axios from 'axios'

export default {
  name: 'home',
  data () {
    return {
      sell: {},
      goods: [],
      ratings: []
    }
  },
  components: {
    sellHeader,
    sellTab
  },
  methods: {
    getSell () {
      axios.get('/api/seller').then(this.getSellSuccess)
      // axios.get('/mock/seller.json').then(this.getSellSuccess)
    },
    getSellSuccess (res) {
      res = res.data
      if (!res) return
      this.sell = res.data
    },
    getRatings () {
      axios.get('/api/ratings').then(this.getRatingsSuccess)
      // axios.get('/mock/ratings.json').then(this.getRatingsSuccess)
    },
    getRatingsSuccess (res) {
      res = res.data
      if (!res) return
      this.ratings = res.data
    },
    getGoods () {
      axios.get('/api/goods').then(this.getGoodsSuccess)
      // axios.get('/mock/goods.json').then(this.getGoodsSuccess)
    },
    getGoodsSuccess (res) {
      res = res.data
      if (!res) return
      this.goods = res.data
    }
  },
  computed: {
    tabs () {
      return [{
        label: '商品',
        component: sellGoods,
        data: {
          goods: this.goods
        }
      }, {
        label: '评论',
        component: sellRatings,
        data: {
          ratings: this.ratings
        }
      }, {
        label: '商家',
        component: sellShop,
        data: {
          sell: this.sell
        }
      }]
    }
  },
  mounted () {
    this.getSell()
    this.getGoods()
    this.getRatings()
  }
}
</script>

<style scoped>

</style>
